package cn.iocoder.yudao.module.shop.controller.admin.masterstatistics;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.shop.controller.admin.masterstatistics.vo.*;
import cn.iocoder.yudao.module.shop.dal.dataobject.masterstatistics.ShopMasterStatisticsDO;
import cn.iocoder.yudao.module.shop.convert.masterstatistics.ShopMasterStatisticsConvert;
import cn.iocoder.yudao.module.shop.service.masterstatistics.ShopMasterStatisticsService;

@Tag(name = "管理后台 - 艾灸师统计")
@RestController
@RequestMapping("/shop/master-statistics")
@Validated
public class ShopMasterStatisticsController {

    @Resource
    private ShopMasterStatisticsService masterStatisticsService;

    @PostMapping("/create")
    @Operation(summary = "创建艾灸师统计")
    @PreAuthorize("@ss.hasPermission('shop:master-statistics:create')")
    public CommonResult<Long> createMasterStatistics(@Valid @RequestBody ShopMasterStatisticsCreateReqVO createReqVO) {
        return success(masterStatisticsService.createMasterStatistics(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新艾灸师统计")
    @PreAuthorize("@ss.hasPermission('shop:master-statistics:update')")
    public CommonResult<Boolean> updateMasterStatistics(@Valid @RequestBody ShopMasterStatisticsUpdateReqVO updateReqVO) {
        masterStatisticsService.updateMasterStatistics(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除艾灸师统计")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('shop:master-statistics:delete')")
    public CommonResult<Boolean> deleteMasterStatistics(@RequestParam("id") Long id) {
        masterStatisticsService.deleteMasterStatistics(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得艾灸师统计")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('shop:master-statistics:query')")
    public CommonResult<ShopMasterStatisticsRespVO> getMasterStatistics(@RequestParam("id") Long id) {
        ShopMasterStatisticsDO masterStatistics = masterStatisticsService.getMasterStatistics(id);
        return success(ShopMasterStatisticsConvert.INSTANCE.convert(masterStatistics));
    }

    @GetMapping("/list")
    @Operation(summary = "获得艾灸师统计列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('shop:master-statistics:query')")
    public CommonResult<List<ShopMasterStatisticsRespVO>> getMasterStatisticsList(@RequestParam("ids") Collection<Long> ids) {
        List<ShopMasterStatisticsDO> list = masterStatisticsService.getMasterStatisticsList(ids);
        return success(ShopMasterStatisticsConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得艾灸师统计分页")
    @PreAuthorize("@ss.hasPermission('shop:master-statistics:query')")
    public CommonResult<PageResult<ShopMasterStatisticsRespVO>> getMasterStatisticsPage(@Valid ShopMasterStatisticsPageReqVO pageVO) {
        PageResult<ShopMasterStatisticsDO> pageResult = masterStatisticsService.getMasterStatisticsPage(pageVO);
        return success(ShopMasterStatisticsConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出艾灸师统计 Excel")
    @PreAuthorize("@ss.hasPermission('shop:master-statistics:export')")
    @OperateLog(type = EXPORT)
    public void exportMasterStatisticsExcel(@Valid ShopMasterStatisticsExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<ShopMasterStatisticsDO> list = masterStatisticsService.getMasterStatisticsList(exportReqVO);
        // 导出 Excel
        List<ShopMasterStatisticsExcelVO> datas = ShopMasterStatisticsConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "艾灸师统计.xls", "数据", ShopMasterStatisticsExcelVO.class, datas);
    }

}
